package com.dmyang.controller;

import com.dmyang.entity.HyArticle;
import com.dmyang.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 后台系统页面跳转的Controller
 * Created by brss on 2017/8/2.
 */
@RequestMapping("admin")
@Controller
public class AdminPageController {

    @Autowired
    private ArticleService articleService;

    /**
     * 后台管理首页
     *
     * @return
     */
    @RequestMapping("/index")
    public String adminIndex() {
        return "adminHome";
    }

    /**
     * 跳转到文章管理页面
     *
     * @return
     */
    @RequestMapping("/adminManageArticle")
    public String adminManageArticle() {
        return "adminManageArticle";
    }

    /**
     * 跳转到博文表单页面
     *
     * @return
     */
    @RequestMapping("/adminArticleForm")
    public String adminAddArticle(String type, Integer id, Model model) {
        if(type.equals("new")){
            model.addAttribute("submitUrl","/article/add");//新增一条文章的url
            model.addAttribute("draftUrl","/article/addDraft");//插入一条草稿的url
        }else if (type.equals("edit")){
            model.addAttribute("submitUrl","/article/modify");//修改一条文章的url
            model.addAttribute("draftUrl","/article/modifyDraft");//修改一条草稿的url
            model.addAttribute("articleId",id);
            HyArticle article = null;
            try {
                article = articleService.findArticleById(id);
            } catch (Exception e) {
                e.printStackTrace();
            }
            model.addAttribute("key",article);
        }
        return "adminArticleForm";
    }

    /**
     * 跳转到分类管理页面
     *
     * @return
     */
    @RequestMapping("/adminManageCategory")
    public String adminManageCategory() {
        return "adminManageCategory";
    }

    /**
     * 跳转到标签管理页面
     *
     * @return
     */
    @RequestMapping("/adminManageTag")
    public String adminManageTag() {return "adminManageTag"; }

    /**
     * 从分类管理页面 跳转 到新增/修改分类表单页面
     *
     * @return
     */
    @RequestMapping("/adminCategoryForm")
    public String adminCategoryForm() {return "adminCategoryForm";}
    /**
     * 从标签理页面 跳转 到新增/修改标签表单页面
     *
     * @return
     */
    @RequestMapping("/adminTagForm")
    public String adminTagForm() {return "adminTagForm";}
}
